var apikey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiZXhwIjozMjg3MjY3NDU3LCJpYXQiOjE3MTA0Njc0NTcsImlzcyI6InN1cGFiYXNlIn0.bC6f6Nq413BezrAKwWUxygDrDsW68-gOjxAewnnIO9w";
		
var Authorization="Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiZXhwIjozMjg3MjY3NDU3LCJpYXQiOjE3MTA0Njc0NTcsImlzcyI6InN1cGFiYXNlIn0.bC6f6Nq413BezrAKwWUxygDrDsW68-gOjxAewnnIO9w";

$(function(){
	var url =  'https://cnpqj0a5g6haaugeu7ag.baseapi.memfiredb.com/rest/v1/t_links?select=*' ;
	$.ajax(
		{
			url: url,
			type: "GET",
			contentType: "jsonp",
			jsonp: "callback",
			jsonpCallback:"flightHandler",
			beforeSend: function(request) {
				request.setRequestHeader("apikey",apikey);
				request.setRequestHeader("Authorization",Authorization);
			},
			success:function (data) {
				console.log(data);
				for (let i = 0; i <data.length; i++) {
					var links = data[i];
					var id = links.id;
					var titile = links.title;
					var url = links.url;
					var des = links.des;
					var html = '<a url="' + url + '" title="'+ des +'" id="'+id+'" onclick="linkClick(this)" href="javascript:void(0)">' + titile + '</a><br/>';
					$("#linksDiv").append(html)
				}
			},
			error:function (data) {
				alert("请求失败")
			}
		}
	)
})



function linkClick(a) {
	var url = $(a).attr('url');
	var title = $(a).attr('title');
	var id = a.id;
	console.log("url: " + url + ", id: " + id);

//	$.post("/linkClick", {"id": id}, function (data) {
//		console.log(data);
//		window.open(url, "_blank");
//	});

   window.open(url, "_blank");
}